<?php

/**
 * CrossApps helpers
 * @package    infectamic
 * @author     Loic Chardonnet <loic.chardonnet@gmail.com>
 */

/**
 * Return a link to the app
 * @param <string> $_appName The name of the wanted app
 * @return <string> The generated link
 */
function cross_apps_link($_appName) {
    // Scripts initialization.
    $scripts = array (
        'backend'   => array ('noname' => false),
        'game'      => array ('noname' => false),
        'frontend'  => array ('noname' => true),
    );

    // Getting the working environment.
    $env = sfConfig::get('sf_environment');

    // Getting the wanted script
    $link = 'backend';
    if (array_key_exists($_appName, $scripts) === true) {
        $link = $_appName;
    }

    // Checking the environment and the noname option.
    if ($env === 'prod' && $scripts[$_appName]['noname'] === true) {
        $link = '';
    }
    if ($env !== 'prod') {
        $link = "{$link}_{$env}";
    }
    if ($scripts[$_appName]['noname'] === false || $env !== 'prod') {
        $link = "{$link}.php";
    }

    return (public_path('', true) . $link);
}
